#include "../Tools/GLHeaders.hpp"
#include "ModelLeftFoot.hpp"
#include <cmath>

ModelLeftFoot::ModelLeftFoot(void){
	activate = false;	
  list_id = glGenLists(1); // create one DisplayList
  glNewList(list_id, GL_COMPILE);
  GLfloat pt00[] = {-0.5f,-1.0f, 3.0f};
  GLfloat pt01[] = { 0.5f,-1.0f, 3.0f};
  GLfloat pt02[] = { 1.0f,-1.0f, 0.75f};
  GLfloat pt03[] = { 1.0f,-1.0f,-1.0f};
  GLfloat pt04[] = { 0.5f,-1.0f,-1.5f};
  GLfloat pt05[] = {-0.5f,-1.0f,-1.5f};
  GLfloat pt06[] = {-1.0f,-1.0f,-1.0f};
  GLfloat pt07[] = {-1.0f,-1.0f, 0.75f};

  GLfloat pt10[] = {-0.5f, 0.0f, 2.5f};
  GLfloat pt11[] = { 0.5f, 0.0f, 2.5f};
  GLfloat pt12[] = { 1.0f, 0.0f, 0.75f};
  GLfloat pt13[] = { 1.0f, 0.0f,-1.0f};
  GLfloat pt14[] = { 0.5f, 0.0f,-1.5f};
  GLfloat pt15[] = {-0.5f, 0.0f,-1.5f};
  GLfloat pt16[] = {-1.0f, 0.0f,-1.0f};
  GLfloat pt17[] = {-1.0f, 0.0f, 0.75f};

  glBegin(GL_TRIANGLES);
  glNormal3f( 0.0f, 0.0f, 1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00); // front
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);

  glNormal3f( 1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01); // front right
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);

  glNormal3f( 1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02); // right
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);

  glNormal3f( 1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03); // back right
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);

  glNormal3f( 0.0f, 0.0f,-1.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04); // back
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04);

  glNormal3f(-1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05); // back left
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);

  glNormal3f(-1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06); // left
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);

  glNormal3f(-1.0f, 0.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07); // front left
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);

  glNormal3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10); // top front
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt11);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt10);

  glNormal3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17); // top
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt12);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt17);

  glNormal3f( 0.0f, 1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16); // top back
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt13);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt14);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt15);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt16);

  glNormal3f( 0.0f,-1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02); // botton front
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt01);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt00);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);

  glNormal3f( 0.0f,-1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03); // botton
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt02);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt07);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);

  glNormal3f( 0.0f,-1.0f, 0.0f);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04); // botton back
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt03);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt06);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt05);
  glColor3f(0.4f, 0.4f, 0.4f);glVertex3fv(pt04);
  glEnd();
  glEndList();
 }

ModelLeftFoot::~ModelLeftFoot(void){
  glDeleteLists(list_id,1);
}

void ModelLeftFoot::Draw(void){
	glPushAttrib(GL_COLOR_BUFFER_BIT|GL_CURRENT_BIT|GL_TEXTURE_BIT);	
	glDisable(GL_TEXTURE_2D); 
	if(activate)
		glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	else
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);

  glCallList(list_id);
	glPopAttrib();
}

void ModelLeftFoot::Activate(void){
	activate = true;
}

void ModelLeftFoot::Desactivate(void){
	activate = false;
}
